//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#pragma package(smart_init)
#pragma resource "*.dfm"
//---------------------------------------------------------------------------
#include "CSupprLogMenu.h"
//---------------------------------------------------------------------------
__fastcall TvSSupprLogMenu::TvSSupprLogMenu(TComponent* Owner)
    : TForm(Owner)
{
    try{
        lText->Caption = MSG;
        TZZMySqlQuery * MaRequete = NULL;
        MaRequete = new TZZMySqlQuery( (TComponent*)0);
        MaRequete->Database = dmWebHelp->dbWebHelp;

        //Insertion dans la table référence
        //---------------------------------
        MaRequete->Sql->Text =  "select logiciels.log_nom, logiciels.log_code "
                                "from logiciels "
                                    "left outer join versions on (logiciels.log_code=versions.log_code) "
                                "where versions.log_code is null";
        MaRequete->Open();
        MaRequete->First();

        while(!MaRequete->Eof) {
            cbLogiciel->Items->AddObject( asRequete(0), (TObject*)nRequete(1) );
            MaRequete->Next();
        }

        MaRequete->Sql->Clear();
        MaRequete->Close();

        if(MaRequete) {delete MaRequete; MaRequete = NULL;}
    }catch( Exception &e ) {
        EIC_DISPLAY_EXCEPTION(e);
    }
}
//---------------------------------------------------------------------------
void __fastcall TvSSupprLogMenu::Supprimer( void )
{
    try{
        lText->Caption = MSG;
        TZZMySqlQuery * MaRequete = NULL;
        MaRequete = new TZZMySqlQuery( (TComponent*)0);
        MaRequete->Database = dmWebHelp->dbWebHelp;

        //Insertion dans la table référence
        //---------------------------------
        MaRequete->Sql->Text =  (AnsiString)"delete from logiciels where log_code = "+(int)cbLogiciel->Items->Objects[cbLogiciel->ItemIndex];
        MaRequete->ExecSql();
        MaRequete->Sql->Clear();

        MaRequete->Sql->Text = "Commit"; 
        MaRequete->ExecSql();
        MaRequete->Sql->Clear();

        MaRequete->Close();

        if(MaRequete) {delete MaRequete; MaRequete = NULL;}
    }catch( Exception &e ) {
        EIC_DISPLAY_EXCEPTION(e);
    }
}
//---------------------------------------------------------------------------
void __fastcall TvSSupprLogMenu::BitBtn1Click(TObject *Sender)
{
    try{
        if(cbLogiciel->ItemIndex != AUCUNE_SELECTION){
            Supprimer();
            ModalResult = mrOk;
        }else {
            MessageDlg("Veuillez sélectionner un logiciel à supprimer.", mtWarning, TMsgDlgButtons() << mbOK, 0);
            ModalResult = mrNone;
        }
    }catch( Exception &e ) {
        EIC_DISPLAY_EXCEPTION(e);
    }
}
//---------------------------------------------------------------------------

